# -*- coding:utf-8 -*-
#import md5
import hashlib

API_SIGN_KEY="0e64979e28a511e7b4a652540083dd32"
'''
#md5加密
def md5_str(_str):
    #src = 'this is a md5 test.'
    m1 = md5.new()
    m1.update(_str)
    res_str=m1.hexdigest()
    return res_str

    # m2 = hashlib.md5()
    # m2.update(_str)
    # res_str_2=m1.hexdigest()
    # return [res_str,res_str_2,res_str==res_str_2]
    '''
#生成签名{'account':'asa','passwaord':'12312312','icon':'001'}
def set_sign(params):
     secret_key = API_SIGN_KEY
     keys = params.keys()
     keys.sort()
     values = [str(params[k]) for k in keys if k!='sign']
     #values = [str(params[k]) if not isinstance(k, basestring) else k for k in keys if k!='sign']
     #values = [str(params[k]) if not isinstance(k, basestring) else params[k] for k in keys if k!='sign']
     values.append(secret_key)
     return hashlib.md5('|'.join(values)).hexdigest()
#tmp_post_obj={'account':'asa','passwaord':'12312312','icon':'001','sign':'sasasfasfasa'}
def check_sign(args):
    a=set_sign(args)
    if a ==args['sign']:
        return 1
    else:
        return 0

# test_data = {'account':'test01','password':'123s55s','icon':'001','sign':'4d2489536be29c07a3ba6ad0f9e2dfda'}
#
# a = check_sign(test_data)
# print a
#test_data = {'user_id':'1','sign':'fcea9bbbe329afe0463fc2e1d24a1f21'}
#print(set_sign(test_data))
# game_data = {'user_id':11,'sign':''}
# print set_sign(game_data)
data = {'uid':'ceshi01','agent_account':'test'}
print set_sign(data)